#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	int answer[100];
	int score[100][100];
	int is[100];
	int i, j;
	for (j = 0; j < m; j++)
	{
		scanf("%d", &answer[j]);
	}
	for (j = 0; j < m; j++)
	{
		scanf("%d", &is[j]);
	}
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			scanf("%d", &score[i][j]);
		}
	}
	int sum;
	for (i = 0; i < n; i++)
	{
		sum = 0;
		for (j = 0; j < m; j++)
		{
			if (is[j] == score[i][j])
			{
				sum += answer[j];
			}
		}
		printf("%d\n", sum);
	}
	return 0;
}